package com.turnengine.client.local.action.command;

import org.apache.commons.lang.builder.CompareToBuilder;
import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;

/**
 * The Add Action.
 */
public class AddAction implements IAddAction {

	/** The command id. */
	public static final short COMMAND_ID = 1001;

	/** The login id. */
	private long loginId;
	/** The instance id. */
	private int instanceId;
	/** The action id. */
	private int actionId;
	/** The turns. */
	private int turns;
	/** The limit. */
	private int limit;

	/**
	 * Creates a new Add Action.
	 */
	public AddAction() {
	}

	/**
	 * Creates a new Add Action.
	 * @param loginId the login id
	 * @param instanceId the instance id
	 * @param actionId the action id
	 * @param turns the turns
	 * @param limit the limit
	 */
	public AddAction(long loginId, int instanceId, int actionId, int turns, int limit) {
		setLoginId(loginId);
		setInstanceId(instanceId);
		setActionId(actionId);
		setTurns(turns);
		setLimit(limit);
	}

	/**
	 * Creates a new Add Action.
	 * @param iAddAction the i add action
	 */
	public AddAction(IAddAction iAddAction) {
		setLoginId(iAddAction.getLoginId());
		setInstanceId(iAddAction.getInstanceId());
		setActionId(iAddAction.getActionId());
		setTurns(iAddAction.getTurns());
		setLimit(iAddAction.getLimit());
	}

	/**
	 * Returns the login id.
	 * @return the login id.
	 */
	public long getLoginId() {
		return loginId;
	}

	/**
	 * Returns the instance id.
	 * @return the instance id.
	 */
	public int getInstanceId() {
		return instanceId;
	}

	/**
	 * Returns the action id.
	 * @return the action id.
	 */
	public int getActionId() {
		return actionId;
	}

	/**
	 * Returns the turns.
	 * @return the turns.
	 */
	public int getTurns() {
		return turns;
	}

	/**
	 * Returns the limit.
	 * @return the limit.
	 */
	public int getLimit() {
		return limit;
	}

	/**
	 * Sets the login id.
	 * @param loginId the login id to set.
	 */
	public void setLoginId(long loginId) {
		this.loginId = loginId;
	}

	/**
	 * Sets the instance id.
	 * @param instanceId the instance id to set.
	 */
	public void setInstanceId(int instanceId) {
		this.instanceId = instanceId;
	}

	/**
	 * Sets the action id.
	 * @param actionId the action id to set.
	 */
	public void setActionId(int actionId) {
		this.actionId = actionId;
	}

	/**
	 * Sets the turns.
	 * @param turns the turns to set.
	 */
	public void setTurns(int turns) {
		this.turns = turns;
	}

	/**
	 * Sets the limit.
	 * @param limit the limit to set.
	 */
	public void setLimit(int limit) {
		this.limit = limit;
	}

	/**
	 * Returns the hash code.
	 * @return the hash code.
	 */
	@Override
	public int hashCode() {
		HashCodeBuilder hash = new HashCodeBuilder(383, 37);
		hash.append(loginId);
		hash.append(instanceId);
		hash.append(actionId);
		hash.append(turns);
		hash.append(limit);
		return hash.toHashCode();
	}

	/**
	 * Returns true if this is equal to the given object.
	 * @param object the object to compare.
	 * @return true if this is equal to the given object.
	 */
	@Override
	public boolean equals(Object object) {
		if (object == this) {
			return true;
		}
		if (object instanceof AddAction) {
			AddAction compare = (AddAction) object;
			EqualsBuilder equals = new EqualsBuilder();
			equals.append(this.loginId, compare.loginId);
			equals.append(this.instanceId, compare.instanceId);
			equals.append(this.actionId, compare.actionId);
			equals.append(this.turns, compare.turns);
			equals.append(this.limit, compare.limit);
			return equals.isEquals();
		}
		return false;
	}

	/**
	 * Compare this to the given object.
	 * @param compare the object to compare to.
	 * @return the result of the comparison.
	 */
	@Override
	public int compareTo(IAddAction compare) {
		CompareToBuilder builder = new CompareToBuilder();
		builder.append(this.loginId, compare.getLoginId());
		builder.append(this.instanceId, compare.getInstanceId());
		builder.append(this.actionId, compare.getActionId());
		builder.append(this.turns, compare.getTurns());
		builder.append(this.limit, compare.getLimit());
		return builder.toComparison();
	}

	/**
	 * Returns this as a string.
	 * @return this as a string.
	 */
	@Override
	public String toString() {
		ToStringBuilder string = new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE);
		string.append("loginId", loginId);
		string.append("instanceId", instanceId);
		string.append("actionId", actionId);
		string.append("turns", turns);
		string.append("limit", limit);
		return string.toString();
	}

	public short getCommandId() {
		return COMMAND_ID;
	}
}
